/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fr.sorbonne.inf1.tp3.model.distant.application;

import fr.sorbonne.inf1.tp3.model.InterfaceApplication;
import fr.sorbonne.inf1.tp3.model.distant.protocole.InterfaceProtocoleClient;
import fr.sorbonne.inf1.tp3.model.distant.protocole.exception.*;
import fr.sorbonne.inf1.tp3.model.exception.*;

/**
 *
 * @author Rich
 */
public class ApplicationDistante implements InterfaceApplication{
    
    private InterfaceProtocoleClient protocole;
    
    public ApplicationDistante(InterfaceProtocoleClient pProto){
        this.protocole = pProto;
    }

    @Override
    public Double calculerAnnuite(Double pMontant, int pNb_annee, Double pTaux) throws fr.sorbonne.inf1.tp3.model.exception.InternalErrorException, AnnuiteApplicationException, MontantApplicationException, TauxApplicationException, NbAnneesApplicationException, CalculAnnuiteApplicationException {
        Double result= 0.0;
        
        try {
            protocole.demandeCalculAnnuite(pMontant, pNb_annee, pTaux);
        } catch (SendProtocolException ex) {
            throw new InternalErrorException();
        }
        try {
            result = protocole.recuperer_resultat();
        } catch (AnnuiteException ex) {
            throw new AnnuiteApplicationException();
        } catch (ClassCastException ex) {
            throw new InternalErrorException();
        } catch (MontantException ex) {
            throw new MontantApplicationException();
        } catch (TauxException ex) {
            throw new TauxApplicationException();
        } catch (NbAnneesException ex) {
            throw new NbAnneesApplicationException();
        } catch (CalculAnnuiteException ex) {
            throw new CalculAnnuiteApplicationException();
        } catch (ReceiveProtocolException ex) {
            throw new InternalErrorException();
        }
        return result;
    }

    @Override
    public Double calculerNbAnnees(Double pMontant, Double pTaux, int pAnnuite) throws InternalErrorException, AnnuiteApplicationException, MontantApplicationException, TauxApplicationException, NbAnneesApplicationException, CalculAnnuiteApplicationException {
        Double result= 0.0;
        
        try {
            protocole.demandeCalculNbAnnees(pMontant, pTaux, pAnnuite);
        } catch (SendProtocolException ex) {
            throw new InternalErrorException();
        }
        try {
            protocole.recuperer_resultat();
        } catch (AnnuiteException ex) {
            throw new AnnuiteApplicationException();
        } catch (ClassCastException ex) {
            throw new InternalErrorException();
        } catch (MontantException ex) {
            throw new MontantApplicationException();
        } catch (TauxException ex) {
            throw new TauxApplicationException();
        } catch (NbAnneesException ex) {
            throw new NbAnneesApplicationException();
        } catch (CalculAnnuiteException ex) {
            throw new CalculAnnuiteApplicationException();
        } catch (ReceiveProtocolException ex) {
            throw new InternalErrorException();
        }
        
        return result;
    }

    
}
